package lab03.test13;

import java.sql.*;

public class Test {
    public static void main(String[] args) {

        Connection connection=null;
        Statement statement=null;
        ResultSet resultSet=null;
      String sql1="SELECT* from t_student";
        String sql2="delete from t_student where id=5";
        String sql3="update t_student set department='信息与工程学院' where id=3 ";
 //       String sql="insert into "+ "t_student(real_name,age,gender,department,stu_no)"+
//                "values('王明',20,1,'信息工程学院','1606101109')";
        try {
            Class.forName("com.mysql.jdbc.Driver");
            connection= DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/java_2017",
                    "root",
                    "123456"
            );
            statement=connection.createStatement();
            //ResultSet:查
            resultSet = statement.executeQuery(sql1);
            statement.execute(sql2);
            statement.execute(sql3);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        finally {
            try {
                statement.close();
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
